package com.panda.takeaway.controller;

import com.panda.takeaway.entity.dto.CommonResult;
import com.panda.takeaway.entity.po.*;
import com.panda.takeaway.entity.vo.*;
import com.panda.takeaway.service.BatchService;
import com.panda.takeaway.service.ShopSchoolService;
import com.panda.takeaway.service.ShopService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author John
 * @create 2021-08-06-11:59
 */
@RestController
@RequestMapping("/api/shop")
public class ShopController {

    @Resource
    private ShopService shopService;

    @Resource
    private BatchService batchService;

    @Resource
    private ShopSchoolService shopSchoolService;





    @PostMapping("/addShop")
    @PreAuthorize("hasAuthority('shop/addShop')")
    public CommonResult<?> addShop(@RequestBody ShopInfoVo shop) {

        return shopService.addShop(shop);
    }


    @PostMapping("/updateShop")
    @PreAuthorize("hasAuthority('shop/updateShop')")
    public CommonResult<?> updateShop(@RequestBody ShopInfoVo shopInfoVo) {

        return shopService.updateShop(shopInfoVo);
    }



    @PostMapping("/setBatch")
    @PreAuthorize("hasAuthority('shop/setBatch')")
    public CommonResult<?> setBatch(@RequestBody BatchVo batch) {

        return batchService.setBatch(batch);
    }

    @PostMapping("/queryAllShops")
    @PreAuthorize("hasAuthority('shop/queryAllShops')")
    public CommonResult<?> queryAllShops(@RequestBody PageInfoVo pageInfoVo) {
        System.out.println("==================="+pageInfoVo);
        return shopService.queryAllShops(pageInfoVo);
    }


    @PostMapping("/queryShopsBySchool")
    @PreAuthorize("hasAuthority('shop/queryShopsBySchool')")
//    shop/queryShopsBySchool
    public CommonResult<?> queryShopsBySchool(@RequestBody BySchQueryVo bySchQueryVo) {


        return shopService.queryShopsBySchool(bySchQueryVo);

    }

    @GetMapping("/queryBatch")
    @PreAuthorize("hasAuthority('shop/queryBatch')")
    public CommonResult<?> queryBatch(@RequestParam("shopId") Long shopId) {

        return batchService.queryBatch(shopId);
    }


    @PostMapping("/updateBatch")
    @PreAuthorize("hasAuthority('shop/updateBatch')")
    public CommonResult<?> updateBatch(@RequestBody BatchVo batchVo) {

        return batchService.updateBatch(batchVo);
    }

    @PostMapping("/addShopSchool")
    @PreAuthorize("hasAuthority('addShopSchool')")
    public CommonResult<?> addShop(@RequestBody ShopSchool shopSchool) {

        return shopSchoolService.addShopSchool(shopSchool);
    }






    /**
     * 测试使用
     * @return
     */
    @PostMapping("/test")
    public String test(@RequestBody TestVo testVo) {

        return testVo.toString();
    }




}
